#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查基金数据下载结果
"""

import os
import sys
import django  # type: ignore

# 设置Django环境
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, current_dir)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wealth_backend.settings')
django.setup()

from data_service.models import FundInfo, FundInfoDetail, FundNavDetail

def main():
    """检查数据下载结果"""
    print("=== 基金数据下载结果检查 ===")
    
    # 检查基金清单
    fund_count = FundInfo.objects.count()
    print(f"基金清单总数: {fund_count}")
    
    # 检查基金详细信息
    detail_count = FundInfoDetail.objects.count()
    print(f"基金详细信息总数: {detail_count}")
    
    # 检查基金净值
    nav_count = FundNavDetail.objects.count()
    print(f"基金净值记录总数: {nav_count}")
    
    print("\n=== 最新5条基金清单 ===")
    for fund in FundInfo.objects.all()[:5]:
        print(f"{fund.fund_code} - {fund.fund_name}")
    
    print("\n=== 最新5条基金详细信息 ===")
    for detail in FundInfoDetail.objects.all()[:5]:
        print(f"{detail.fund_code} - {detail.fund_name} - {detail.fund_company}")
    
    print("\n=== 数据完整性检查 ===")
    print(f"基金清单下载: {'✓' if fund_count > 0 else '✗'}")
    print(f"基金详细信息下载: {'✓' if detail_count > 0 else '✗'}")
    print(f"基金净值下载: {'✓' if nav_count > 0 else '✗'}")
    
    # 检查字段完整性
    if detail_count > 0:
        sample_detail = FundInfoDetail.objects.first()
        print("\n=== 基金详细信息字段示例 ===")
        print(f"基金代码: {sample_detail.fund_code}")
        print(f"基金名称: {sample_detail.fund_name}")
        print(f"基金全称: {sample_detail.fund_full_name}")
        print(f"成立时间: {sample_detail.establishment_date}")
        print(f"最新规模: {sample_detail.latest_scale}")
        print(f"基金公司: {sample_detail.fund_company}")
        print(f"基金经理: {sample_detail.fund_manager}")
        print(f"托管银行: {sample_detail.custodian_bank}")
        print(f"基金类型: {sample_detail.fund_type}")
        print(f"评级机构: {sample_detail.rating_agency}")
        print(f"基金评级: {sample_detail.fund_rating}")
        print(f"投资策略: {sample_detail.investment_strategy}")
        print(f"投资目标: {sample_detail.investment_objective}")
        print(f"业绩比较基准: {sample_detail.performance_benchmark}")
        print(f"更新日期: {sample_detail.updated_at}")

if __name__ == '__main__':
    main()